from PyQt5.QtWidgets import QApplication,QWidget,QPushButton
from PyQt5.QtCore import Qt,QBasicTimer
import sys
import threading
import time

from forms.component import 进度条

def wrapper_progress(func):
    def wrapper(*args,**kwargs):

        res=func(*args,**kwargs)
        try:
            args[0].进度条.step = 100
        except:
            pass
        return res
    return wrapper

class progress(QWidget):
    def __init__(self):
        super().__init__()
        self.Iint()
    def Iint(self):
        self.ui = 进度条.Ui_Form()
        self.ui.setupUi(self)
        self.setWindowFlags(Qt.WindowTitleHint)
        self.setWindowModality(Qt.ApplicationModal)
        self.windowTitle = '进度'
        self.messageText = '加载中...'
        self.step=0
        self.ui.progressBar.setValue(0)
        self.time1=QBasicTimer()
        self.time1.start(300,self)
    def timerEvent(self, e: 'QTimerEvent') -> None:
        if self.step==100:
            self.time1.stop()
            self.close()
        else:
            self.step+=3
            self.ui.progressBar.setValue(self.step)
            self.setWindowTitle(self.windowTitle)
            self.ui.label.setText(self.messageText)





class 测试窗体(QWidget):
    def __init__(self):
        super(测试窗体, self).__init__()
        self.Iint()
    def Iint(self):
        self.resize(300,400)
        btn=QPushButton('di',self)
        btn.clicked.connect(self.BtnCliked)


    def create_ui_show(self):
        '''呀处理的事务'''

        for i in range(10):
            time.sleep(0.1)
            print(i)
            self.ji2.messageText=str(i)
            self.ji2.windowTitle="dddd"
        self.ji2.step = 100

        # """后面这个是后缀，必须要带上"""
        # for i in range(5):
        #     time.sleep(0.1)
        #     self.ji2.rate = 100



    def BtnCliked(self):
        self.ji2 = progress()
        self.ji2.show()
        thread1 = threading.Thread(target=self.create_ui_show)
        thread1.start()





if __name__=='__main__':
    app = QApplication(sys.argv)
    ji = 测试窗体()
    ji.show()

    sys.exit(app.exec_())

